package com.yun.algorithm.sort;

import java.util.Arrays;

public class E02leetcode1636 {
    public int[] frequencySort(int[] nums) {
        int[] count=new int[201];
        for (int num : nums) {
            count[num+100]++;
        }
        return Arrays.stream(nums).boxed().sorted((a, b) -> {
            int af = count[a + 100];
            int bf = count[b + 100];
            if (af < bf) {
                return -1;
            } else if (af > bf) {
                return 1;
            } else {
                return b - a;
            }
        }).mapToInt(Integer::intValue).toArray();
    }
}
